import socket
import threading
class Client_end:
    def __init__(self,conn_addr=('10.2.1.60',12345)):
        self.ss=socket.socket()
        self.con=conn_addr

    def start(self):
        self.ss.connect(self.con)
        threading.Thread(target=self.recv_msg).start()


    def recv_msg(self):
        while True:
            threading.Thread(target=self.send_msg).start()
            try:
                msg=self.ss.recv(65535)
                print(msg.decode())
            except Exception as e:
                print('发生错误，请重启')
                self.ss.close()

    def send_msg(self):
        msg=input("请输入消息：")
        try:
            self.ss.send(msg.encode())
        except Exception:
            print('发生错误，请重启')
            self.ss.close()
client=Client_end()
client.start()




